// components/song-player/song-player.js
const app = getApp();
const util = require("../../utils/util")
var _that

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    item: { // 属性名
      type: Object,
      value: {}
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    songPic: getApp().globalData.songImg,
    songName: getApp().globalData.correctSongName,
    songAuthor: getApp().globalData.correctSongArtist,
    ifStop: getApp().globalData.ifStop,
  },

  lifetimes: {
    created() {

      this.setData({
        songName: getApp().globalData.correctSongName,
        songAuthor: getApp().globalData.correctSongArtist,
        songPic: getApp().globalData.songImg,
        ifStop: getApp().globalData.ifStop,
      })
      console.log("creat()" + this.data.ifStop)
    },
    attached() {
      _that = this;
      getApp().watch(this.watchBackName, this.watchBackImg, this.watchBackArtist, this.watchBackStop) //注册监听
      this.setData({
        songName: getApp().globalData.correctSongName,
        songAuthor: getApp().globalData.correctSongArtist,
        songPic: getApp().globalData.songImg,
        ifStop: getApp().globalData.ifStop,
      })
      // console.log("attached()" + this.data.ifStop)

    },
    ready() {

    },
    moved() {

    },



  },

  /**
   * 组件的方法列表
   */


  methods: {

    // 点击进入歌曲播放页
    songplaypage() {
      wx.navigateTo({
        url: '/pages/songplay/songplay',
      })
    },

    play_stop() {
      if (this.data.ifStop == true) {
        //已暂停，点击播放
        util.songPlayByUrl();

      } else {

        //已播放，点击暂停
        util.songPause();

      }
      //刷新所在页面
      var page = getCurrentPages().pop();
      if (page != undefined && page != null) {
        page.refreshSongRigon();
      };

    },

    //下一首
    next() {
      util.nextSong();
      //刷新所在页面
      var page = getCurrentPages().pop();
      // console.log(page)
      if (page != undefined && page != null) {
        page.onShow();
      };
    },

    watchBackName: function (value) {
      if (value != _that.data.songName) {
        _that.setData({
          songName: getApp().globalData.correctSongName,
        })
        console.log("更新songplayer组件name")
      }

    },
    watchBackImg: function (value) {
      if (value != _that.data.songPic) {
        _that.setData({
          songPic: getApp().globalData.songImg,
        })
        console.log("更新songplayer组件img")
      }

    },
    watchBackArtist: function (value) {
      if (value != _that.data.songAuthor) {
        _that.setData({
          songAuthor: getApp().globalData.correctSongArtist,
        })
        console.log("更新songplayer组件artist")
      }

    },
    watchBackStop: function (value) {
      if (value != _that.data.ifStop) {
        _that.setData({
          ifStop: getApp().globalData.ifStop,
        })
        console.log("更新songplayer组件ifstop" + _that.data.ifStop)
      }

    },

  }




})